﻿<StackPanel 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:bi="clr-namespace:CoProjectDF.Controls"
    xmlns:local="clr-namespace:CoProjectDF.Controls"
    xmlns:login="clr-namespace:CoProjectDF.Views.Login"
    x:Class="CoProjectDF.Views.Login.LoginForm"
    KeyDown="LoginForm_KeyDown"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"
    d:DataContext="{d:DesignInstance login:LoginViewModel, IsDesignTimeCreatable=True}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="27" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <bi:BusyIndicator x:Name="busyIndicator" 
                             BusyContent="{Binding Path=ApplicationStrings.BusyIndicatorLoggingIn, Source={StaticResource ResourceWrapper}}"
                             IsBusy="{Binding IsLoggingIn}">
            
            <StackPanel Orientation="Vertical">
                <local:CustomDataForm x:Name="loginForm"
                                      Padding="10,10,20,0"
                                      CurrentItem="{Binding LoginInfo}"
                                      IsEnabled="{Binding CanLogin}"
                                      AutoEdit="True" CommandButtonsVisibility="None" HeaderVisibility="Collapsed" 
                                      AutoGeneratingField="LoginForm_AutoGeneratingField" 
                                      Style="{StaticResource LoginDataFormStyle}" DescriptionViewerPosition="BesideContent"
                                      >
                </local:CustomDataForm>
            </StackPanel>
        </bi:BusyIndicator>

        <!-- Added to show user error messages -->
        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center"  
                    VerticalAlignment="Center" Margin="3">
            <TextBlock x:Name="status" Text="{Binding Status}" Margin="0"/>
        </StackPanel>
        
        <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,10,0">
            <Button x:Name="loginButton" Content="{Binding Path=ApplicationStrings.OKButton, Source={StaticResource ResourceWrapper}}" Click="LoginButton_Click" Style="{StaticResource RegisterLoginButtonStyle}" IsEnabled="{Binding Path=CanLogin}" />
            <Button x:Name="loginCancel" Content="{Binding Path=ApplicationStrings.CancelButton, Source={StaticResource ResourceWrapper}}" Click="CancelButton_Click" Style="{StaticResource RegisterLoginButtonStyle}" />
        </StackPanel>

        <StackPanel Grid.Row="2" Style="{StaticResource RegisterLoginLinkPanelStyle}">
            <TextBlock Text="{Binding Path=ApplicationStrings.NotRegisteredYetLabel, Source={StaticResource ResourceWrapper}}" Style="{StaticResource CommentStyle}"/>
            <HyperlinkButton x:Name="registerNow" Content="{Binding Path=ApplicationStrings.RegisterNowButton, Source={StaticResource ResourceWrapper}}" Click="RegisterNow_Click" IsEnabled="{Binding IsLoggingIn, Converter={StaticResource NotOperatorValueConverter}}" />
        </StackPanel>
    </Grid>
</StackPanel>